﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Timers;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GOA_Client
{
    class Exercise
    {
        System.Timers.Timer timer;
        public ClientGUI form;
        public SerialPort serial;
        public int powervalue;
        
        public Exercise(ClientGUI form, SerialPort serial) {
            this.form = form;
            this.serial = serial;
            startExercise();
        }

        public void startExercise() {
            timer = new System.Timers.Timer(3600);

            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            timer.Enabled = true;
        }

        public void update() {
            if (powervalue < 400)
            {
                serial.WriteLine("PW " + powervalue);
                powervalue += 5;
            }
            else {
                MessageBox.Show("Exercise", "End of Exercise",
                System.Windows.Forms.MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                timer.Stop();
                form.stopAll();
            }
        }

        public void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            update();
        }
    }
}
